import Sequelize from 'sequelize';
import express from 'express';
import { statusList, sequelizeStatus } from '../../common/status'; // 状态码对照
import { TradeForeign } from '../../modal/index'; // 数据库实体类
import { checkPermission, createOrderNumber } from '../../utils/utils'; // 工具类

const router = express.Router();
const permission = ["all"];

router.post('/', async function (Request, Response, next) {
  // 权限校验
  await checkPermission(Request, Response, permission)
  let param = Request.body;
  TradeForeign.Modal.upsert(param).then(res => {
    // res为true则新增，false则更新
    Response.json({
      data: res,
      message: "success"
    });
  }).catch(err => {
    console.log(err)
    Response.status(500).send({ message: sequelizeStatus[err.name] || statusList[500] || err.name });
  });
});

module.exports = router;